/* data provider interface for mapping data to GUI automaticly */

jsx3.lang.Class.defineInterface(
	"ux.cdb.admin.dataautomate.IDataProvider",
	null,
	function(plugin, plugin_prototype) {

		plugin_prototype.registerConsumer = function(consumer) {
			this.getAllConsumers().remove(consumer);
			this.getAllConsumers().add(consumer);
		};

		plugin_prototype.getAllConsumersIterator = function() {
			if(!this.consumers) {
				this.consumers = new jsx3.util.List(0);
			}
			return this.consumers.iterator();
		};

		plugin_prototype.getAllConsumers = function() {
			if(!this.consumers) {
				this.consumers = new jsx3.util.List(0);
			}
			return this.consumers;
		};

		plugin_prototype.unregisterConsumer = function(consumer) {
			this.getAllConsumers().remove(consumer);
		};

		plugin_prototype.registerExtractor = function(extractor) {
			this.getAllExtractors().remove(extractor);
			this.getAllExtractors().add(extractor);
		};

		plugin_prototype.getAllExtractorsIterator = function() {
			if(!this.extractors) {
				this.extractors = new jsx3.util.List(0);
			}
			return this.extractors.iterator();
		};

		plugin_prototype.getAllExtractors = function() {
			if(!this.extractors) {
				this.extractors = new jsx3.util.List(0);
			}
			return this.extractors;
		};

		plugin_prototype.unregisterExtractor = function(extractor) {
			this.getAllExtractors().remove(extractor);
		};
		
		plugin_prototype.onDestroy = function () {
            /* @JSC :: begin DEBUG */
			jsx3.log("ux.cdb.admin.dataautomate.IDataProvider onDestroy ");
            /* @JSC :: end */
		};

		plugin_prototype.setData = function(cdf){
			var cIter = this.getAllConsumersIterator();
			while(cIter.hasNext()) {
				cIter.next().setData(cdf);
			}
		};

        plugin_prototype.setDataByObject = function(data) {
			var cIter = this.getAllConsumersIterator();
			while(cIter.hasNext()) {
				cIter.next().setDataByObject(data);
			}
        };
		
		plugin_prototype.getData = function(){
			var doc = jsx3.xml.CDF.Document.newDocument();
            doc.insertRecord(this.getDataAsObject(), "jsxroot");
			return doc;
		};

        plugin_prototype.getDataAsObject = function() {
            var eIter = this.getAllExtractorsIterator();
            var record = {};
            while(eIter.hasNext()) {
                var ext = eIter.next();
                var att = ext.getExtractDataAttributeName();
                var value = ext.getData();
                record[att] = value;
            }
            return record;
        };
		
		//abstract method for validation,need to implement in subclass
		plugin_prototype.doValidate = jsx3.lang.Method.newAbstract();
		
		
	});
